package cn.com.cifi.mars.service.impl;

import cn.com.cifi.mars.bean.dto.ProjectByStagesDto;
import cn.com.cifi.mars.entity.MdmProjectPatner;
import cn.com.cifi.mars.entity.common.ProjectByStages;
import cn.com.cifi.mars.mapper.mars.ApprovalBillMapper;
import cn.com.cifi.mars.mapper.mars.ProjectBasicInfoMapper;
import cn.com.cifi.mars.mapper.mars.ProjectByStagesMapper;
import cn.com.cifi.mars.service.ProjectBasicService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ProjectBasicServiceImpl extends ServiceImpl<ProjectBasicInfoMapper,MdmProjectPatner> implements ProjectBasicService {

    @Autowired
    ProjectBasicInfoMapper projectBasicInfoMapper;
    @Autowired
    ProjectByStagesMapper projectByStagesMapper;
    @Autowired
    ApprovalBillMapper approvalBillMapper;

    //查询权益比例
    @Override
    public MdmProjectPatner selecteQuityRatio(String ProjectId) {
        MdmProjectPatner projectPatner = null;
        if (null != ProjectId && ProjectId != ""){
            projectPatner = projectBasicInfoMapper.selectQuityRatio(ProjectId,"旭辉");

        }
        return projectPatner;
    }
    /**
     * 查询权益比例
     * @param projectId
     * @return
     */
    @Override
    public String getEquityRatioRate(String projectId) {
        BigDecimal equityRatio = BigDecimal.ZERO;
        MdmProjectPatner projectPatner = this.selecteQuityRatio(projectId);
        if (projectPatner != null) {
            if (projectPatner.getEquityRatio() != null) {
                equityRatio = projectPatner.getEquityRatio();
            }
        }
        return equityRatio.toString();
    }


    //查询项目树字符串
    @Override
    public List<String> selectFullPath(String projectId) {
    	List<String>orgids=new ArrayList<>();
    	orgids.add(projectId);
    	List<ProjectByStagesDto> projectByStagesDtoList = projectByStagesMapper.selectByOrgdepids(orgids);
        List<String> fullPath = null;
        if (projectByStagesDtoList.size()>0){
            String orgnofullpath = projectByStagesDtoList.get(0).getOrgnofullpath();
            if(StringUtils.isNotBlank(orgnofullpath)){
                String []str=orgnofullpath.split("-");
                fullPath = Arrays.asList(str);
            }
        }
        return fullPath;
    }

    @Override
    public String selectRegionName(List<String> str,String hrOrgTypeId) {
    	if(CollectionUtils.isEmpty(str)){
        	return "";
        }
        return projectByStagesMapper.selectRegionName(str,hrOrgTypeId);
    }

    @Override
    public String selectRegionId(List<String> str,String hrOrgTypeId) {
        return projectByStagesMapper.selectRegionId(str,hrOrgTypeId);
    }

    //查询审批说明
    @Override
    public String selectDescriptionByBusinessKey(String businessKey) {
        String description = approvalBillMapper.selectDescriptionByBusinessKey(businessKey);
        return description;
    }

}
